<?php

namespace App\Validation;

use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Numericality;
use Phalcon\Validation\Validator\InclusionIn;

class MemberPraiseValidation extends BaseValidation
{
	public function initialize()
	{
		$this->add(
			'id',
			new PresenceOf(
				[
					"message" => ":field is required",
					"allowEmpty" => TRUE,
				]	
			)
		);

		$this->add(
			'memebr_id',
			new PresenceOf(
				[
					"message" => ":field is required",
					"allowEmpty" => TRUE,
				]	
			)
		);

		$this->add(
			'table_id',
			new PresenceOf(
				[
					"message" => ":field is required",
					// "allowEmpty" => TRUE,
				]	
			)
		);

		$this->add(
			'list_id',
			new PresenceOf(
				[
					"message" => ":field is required",
					// "allowEmpty" => TRUE,
				]	
			)
		);

		$this->add(
			'praise',
			new PresenceOf(
				[
					"message" => ":field is required",
					"allowEmpty" => TRUE,
				]	
			)
		);

		$this->add(
			"praise",
			new InclusionIn(
				  [
					  "domain" => [-1,1],//-1、点踩 1点赞
					  "message" => ":field is not included in -1 or 1",
				  ]
			)
		);

	}

	//验证之前
	public function beforeValidation($data, $entity, $messages)
    {
        $data->praise = property_exists($data,'praise') ? $data->praise : 1;
        return true;
    }
}